import * as cc from 'cc';
import * as ccenv from 'cc/env'

const isDevelopment = ccenv.DEBUG;
const isProduction = !ccenv.DEBUG;
const isPC = ccenv.MAC || ccenv.WINDOWS || ccenv.LINUX;
const EventClick = isPC ? cc.NodeEventType.MOUSE_DOWN : cc.NodeEventType.TOUCH_START;

export function listenerClick(node: cc.Node, listener: (node: cc.Node) => void, target?: any): () => void {
    const _listener = listener.bind(target, node);
    node.on(EventClick, _listener, node);
    const unbind = () => {
        console.log('listenerClick', 'unbind', EventClick, node.name);
        node.off(EventClick, _listener, node);
    }
    node.once(cc.NodeEventType.NODE_DESTROYED, unbind, node);
    return () => {
        node.off(cc.NodeEventType.NODE_DESTROYED, unbind, node);
        unbind();
    }
}